package cn.javabb.service;

import cn.javabb.common.entity.Student;
import cn.javabb.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: javabb (javabob(a)163.com)
 * @create: 2020/05/28 18:21
 */
@Service
public class StudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询所有
     * @return
     */
    public List<Student> queryAll() {
        return studentMapper.selectAll();
    }

    /**
     * 根据主键查询
     * @param id
     * @return
     */
    public Student queryOne(Integer id){
        return studentMapper.selectByPrimaryKey(id);
    }
    /**
     * 保存
     * @param student
     * @return
     */
    public boolean save(Student student) {
        int result = 0 ;
        if (null != student.getId()) {
            result = studentMapper.updateByPrimaryKeySelective(student);
        }else{
            result = studentMapper.insertSelective(student);
        }
        return result > 0;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public boolean deleteById(Integer id) {
        return studentMapper.deleteByPrimaryKey(id) > 0;
    }

}
